light6 2.2.0
Loading...
Searching...
No Matches
light6.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef LIGHT6_H
29#define LIGHT6_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define LIGHT6_REG_ALS_CONF 0x00
74#define LIGHT6_REG_ALS_THDH_L 0x04
75#define LIGHT6_REG_ALS_THDH_H 0x05
76#define LIGHT6_REG_ALS_THDL_L 0x06
77#define LIGHT6_REG_ALS_THDL_H 0x07
78#define LIGHT6_REG_ALS_DATA_L 0x10
79#define LIGHT6_REG_ALS_DATA_H 0x11
80#define LIGHT6_REG_IR_DATA_L 0x12
81#define LIGHT6_REG_IR_DATA_H 0x13
82#define LIGHT6_REG_VEML6031X01_ID_L 0x14
83#define LIGHT6_REG_VEML6031X01_ID_H 0x15
84#define LIGHT6_REG_INT_FLAG 0x17
85 // light6_reg
87
92
97
102#define LIGHT6_ALS_CONFIG_ALS_IT_3_125_MS 0x0000
103#define LIGHT6_ALS_CONFIG_ALS_IT_6_25_MS 0x1000
104#define LIGHT6_ALS_CONFIG_ALS_IT_12_5_MS 0x2000
105#define LIGHT6_ALS_CONFIG_ALS_IT_25_MS 0x3000
106#define LIGHT6_ALS_CONFIG_ALS_IT_50_MS 0x4000
107#define LIGHT6_ALS_CONFIG_ALS_IT_100_MS 0x5000
108#define LIGHT6_ALS_CONFIG_ALS_IT_200_MS 0x6000
109#define LIGHT6_ALS_CONFIG_ALS_IT_400_MS 0x7000
110#define LIGHT6_ALS_CONFIG_ALS_IT_MASK 0x7000
111#define LIGHT6_ALS_CONFIG_ALS_MODE_AUTO 0x0000
112#define LIGHT6_ALS_CONFIG_ALS_MODE_ACTIVE_FORCE 0x0800
113#define LIGHT6_ALS_CONFIG_ALS_MODE_MASK 0x0800
114#define LIGHT6_ALS_CONFIG_ALS_TRIGGER_OFF 0x0000
115#define LIGHT6_ALS_CONFIG_ALS_TRIGGER_ON 0x0400
116#define LIGHT6_ALS_CONFIG_ALS_TRIGGER_MASK 0x0400
117#define LIGHT6_ALS_CONFIG_ALS_INT_OFF 0x0000
118#define LIGHT6_ALS_CONFIG_ALS_INT_ON 0x0200
119#define LIGHT6_ALS_CONFIG_ALS_INT_MASK 0x0200
120#define LIGHT6_ALS_CONFIG_ALS_ON_TURN_ON 0x0000
121#define LIGHT6_ALS_CONFIG_ALS_ON_TURN_OFF 0x0180
122#define LIGHT6_ALS_CONFIG_ALS_ON_MASK 0x0180
123#define LIGHT6_ALS_CONFIG_ALS_PDDIV_4_4_PD 0x0000
124#define LIGHT6_ALS_CONFIG_ALS_PDDIV_1_4_PD 0x0040
125#define LIGHT6_ALS_CONFIG_ALS_PDDIV_MASK 0x0040
126#define LIGHT6_ALS_CONFIG_ALS_GAIN_X1 0x0000
127#define LIGHT6_ALS_CONFIG_ALS_GAIN_X2 0x0008
128#define LIGHT6_ALS_CONFIG_ALS_GAIN_X0_66 0x0010
129#define LIGHT6_ALS_CONFIG_ALS_GAIN_X0_5 0x0018
130#define LIGHT6_ALS_CONFIG_ALS_GAIN_MASK 0x0018
131#define LIGHT6_ALS_CONFIG_ALS_PERS_1 0x0000
132#define LIGHT6_ALS_CONFIG_ALS_PERS_2 0x0002
133#define LIGHT6_ALS_CONFIG_ALS_PERS_4 0x0004
134#define LIGHT6_ALS_CONFIG_ALS_PERS_8 0x0006
135#define LIGHT6_ALS_CONFIG_ALS_PERS_MASK 0x0006
136#define LIGHT6_ALS_CONFIG_ALS_CAL_OFF 0x0000
137#define LIGHT6_ALS_CONFIG_ALS_CAL_ON 0x0001
138#define LIGHT6_ALS_CONFIG_ALS_CAL_MASK 0x0001
139
144#define LIGHT6_INT_FLAG_AF_DATA_READY 0x08
145#define LIGHT6_INT_FLAG_ALS_IF_L 0x04
146#define LIGHT6_INT_FLAG_ALS_IF_H 0x02
147
152#define LIGHT6_DEVICE_ID 0x0001
153
158#define LIGHT6_ALS_MIN_RES 0.002568f
159
164#define LIGHT6_ALS_CONFIG_DEFAULT ( LIGHT6_ALS_CONFIG_ALS_IT_25_MS | \
165 LIGHT6_ALS_CONFIG_ALS_MODE_AUTO | \
166 LIGHT6_ALS_CONFIG_ALS_TRIGGER_OFF | \
167 LIGHT6_ALS_CONFIG_ALS_INT_OFF | \
168 LIGHT6_ALS_CONFIG_ALS_ON_TURN_ON | \
169 LIGHT6_ALS_CONFIG_ALS_PDDIV_4_4_PD | \
170 LIGHT6_ALS_CONFIG_ALS_GAIN_X1 | \
171 LIGHT6_ALS_CONFIG_ALS_PERS_8 | \
172 LIGHT6_ALS_CONFIG_ALS_CAL_ON )
173#define LIGHT6_THRESHOLD_LOW_DEFAULT 0x0000
174#define LIGHT6_THRESHOLD_HIGH_DEFAULT 0x0000
175
181#define LIGHT6_DEVICE_ADDRESS 0x29
182 // light6_set
184
189
194
199#define LIGHT6_MAP_MIKROBUS( cfg, mikrobus ) \
200 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
201 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
202 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
203 // light6_map // light6
206
211typedef struct
212{
213 // Input pins
214 digital_in_t int_pin;
215
216 // Modules
217 i2c_master_t i2c;
218
219 // I2C slave address
221
222 float als_res;
223
224} light6_t;
225
230typedef struct
231{
232 pin_name_t scl;
233 pin_name_t sda;
234
235 pin_name_t int_pin;
236
237 uint32_t i2c_speed;
238 uint8_t i2c_address;
239
241
246typedef enum
247{
250
252
258
269
283err_t light6_init ( light6_t *ctx, light6_cfg_t *cfg );
284
298
313err_t light6_generic_write ( light6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
314
329err_t light6_generic_read ( light6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
330
340
351
362err_t light6_set_als_config ( light6_t *ctx, uint16_t config );
363
374err_t light6_get_als_config ( light6_t *ctx, uint16_t *config );
375
387err_t light6_set_als_threshold ( light6_t *ctx, uint16_t threshold_low, uint16_t threshold_high );
388
400err_t light6_get_als_threshold ( light6_t *ctx, uint16_t *threshold_low, uint16_t *threshold_high );
401
412err_t light6_get_int_flag ( light6_t *ctx, uint8_t *int_flag );
413
425err_t light6_get_raw_data ( light6_t *ctx, uint16_t *als_data, uint16_t *ir_data );
426
438err_t light6_get_data ( light6_t *ctx, float *als_data, uint16_t *ir_data );
439
440#ifdef __cplusplus
441}
442#endif
443#endif // LIGHT6_H
444 // light6
446
447// ------------------------------------------------------------------------ END
err_t light6_generic_write(light6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Light 6 I2C writing function.
err_t light6_get_als_config(light6_t *ctx, uint16_t *config)
Light 6 Get ALS Configuration function.
err_t light6_init(light6_t *ctx, light6_cfg_t *cfg)
Light 6 initialization function.
err_t light6_set_als_config(light6_t *ctx, uint16_t config)
Light 6 Set ALS Configuration function.
uint8_t light6_get_int_pin(light6_t *ctx)
Light 6 get INT pin function.
err_t light6_generic_read(light6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Light 6 I2C reading function.
err_t light6_check_communication(light6_t *ctx)
Light 6 Check Communication function.
err_t light6_get_int_flag(light6_t *ctx, uint8_t *int_flag)
Light 6 Get Interrupt Flag function.
void light6_cfg_setup(light6_cfg_t *cfg)
Light 6 configuration object setup function.
err_t light6_set_als_threshold(light6_t *ctx, uint16_t threshold_low, uint16_t threshold_high)
Light 6 Set ALS Threshold function.
err_t light6_default_cfg(light6_t *ctx)
Light 6 default configuration function.
err_t light6_get_raw_data(light6_t *ctx, uint16_t *als_data, uint16_t *ir_data)
Light 6 Get Raw Data function.
err_t light6_get_als_threshold(light6_t *ctx, uint16_t *threshold_low, uint16_t *threshold_high)
Light 6 Get ALS Threshold function.
err_t light6_get_data(light6_t *ctx, float *als_data, uint16_t *ir_data)
Light 6 Get Processed Data function.
light6_return_value_t
Light 6 Click return value data.
Definition light6.h:247
@ LIGHT6_OK
Definition light6.h:248
@ LIGHT6_ERROR
Definition light6.h:249
Light 6 Click configuration object.
Definition light6.h:231
uint32_t i2c_speed
Definition light6.h:237
pin_name_t scl
Definition light6.h:232
pin_name_t int_pin
Definition light6.h:235
pin_name_t sda
Definition light6.h:233
uint8_t i2c_address
Definition light6.h:238
Light 6 Click context object.
Definition light6.h:212
float als_res
Definition light6.h:222
digital_in_t int_pin
Definition light6.h:214
i2c_master_t i2c
Definition light6.h:217
uint8_t slave_address
Definition light6.h:220